/* eslint-disable @typescript-eslint/ban-ts-comment */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
const allowedExtensions = ['csv', 'xls', 'xlsx'];

const allowedTypes = [
  'text/csv',
  'application/vnd.ms-excel',
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
];

export function validFileExcelType(fileName: string, fileType: string): boolean {
  // 检查 MIME 类型是否在允许的类型列表中
  if (!allowedTypes.includes(fileType)) {
    // 如果 MIME 类型不在允许的类型列表中，检查文件名后缀
    // @ts-expect-error
    const fileExtension = fileName.split('.').pop().toLowerCase();
    if (!allowedExtensions.includes(fileExtension)) {
      return false;
    }
  }

  return true;
}

// eslint-disable-next-line consistent-return
export function validateFileSize(fileSize: number, maxFileSize: number): boolean {
  if (fileSize > maxFileSize) {
    return false;
  }
  return true;
}
